package com.ldp.designpatterns.review.create.single;

/**
 * @ClassName LazyDoubleCheckSingle
 * @Description 懒加载——双重校验
 * 特点：推荐使用
 * @Author lindipei
 * @Date 2023/10/13 17:28
 */
public class LazyDoubleCheckSingle {
    private static LazyDoubleCheckSingle instance;
    private LazyDoubleCheckSingle(){}

    //提供一个静态的公共方法，加入双重校验，解决线程安全的问题，同事解决懒加载的问题，同时保证了效率，推荐使用
    public static synchronized  LazyDoubleCheckSingle getInstance(){
        if(instance == null){
            synchronized (LazyDoubleCheckSingle.class){
                if(instance ==null){
                    instance = new LazyDoubleCheckSingle();
                }
            }
        }
        return instance;
    }
}
